var options;
var viewer;
var drawableContaine;
var pointId = null;
var pointNo = null;
var xyz = null;
var isInclinometer = null;
var viewId,num,point_icon;
var picPath, pid_point = '',modelLx;

// 初始化模型
function initiModel(viewToken, id, path, nums,modelLxs) {
	// 初始化
	options = new BimfaceSDKLoaderConfig();
	options.viewToken = viewToken;
	viewId = id;
	picPath = path;
	num = nums;
	modelLx = modelLxs;
	BimfaceSDKLoader.load(options, onSDKLoadSucceeded, onSDKLoadFailed);
	createDiv(nums);
}

function onSDKLoadSucceeded(viewMetaData) {
	// 初始化viewer
	var view = document.getElementById('' + viewId + '');
	if(modelLx == null || modelLx){
		var WebAppConfig = new Glodon.Bimface.Application.WebApplication3DConfig();
		WebAppConfig.domElement = view;
		var appEvents = Glodon.Bimface.Viewer.Viewer3DEvent;
	
		var app = new Glodon.Bimface.Application.WebApplication3D(WebAppConfig);
		viewer = app.getViewer();
		app.addView(viewMetaData.viewToken);
	
		// 初始化DrawableContainer
		var drawableConfig = new Glodon.Bimface.Plugins.Drawable.DrawableContainerConfig();
		drawableConfig.viewer = viewer;
		drawableContainer = new Glodon.Bimface.Plugins.Drawable.DrawableContainer(drawableConfig);
		app.addEventListener(appEvents.ViewAdded, function() {
			//   viewer.getComponentProperty("748330", callback)
			app.render();
			if(type_name == '钢支撑'){
				loadSign1();
			}else{
				loadSign();
			}
	
		});
		app.addEventListener(appEvents.MouseClicked, function(objectData) {
			if(!objectData.worldPosition){
				return
			}else {
				if(pointId == null || pointId != -1) {
					return;
				}
	
				//  console.log(objectData, 1);
				var x = objectData.worldPosition.x;
				var y = objectData.worldPosition.y;
				var z = objectData.worldPosition.z;
				xyz = x + "," + y + "," + z;
				if(point_icon){
					var imgs= publicUrl +'file/'+point_icon
				}else{
					var imgs= "../../common/image/circularPointBlue.png"
				}
				drawPoint(pointId, pointNo, isInclinometer, xyz, true, imgs);
	
			}
	
		});
		setBackgroundColor()
	}else if(!modelLx){
		var WebAppConfig = new Glodon.Bimface.Application.WebApplication2DConfig();
		WebAppConfig.domElement = view;
		var appEvents = Glodon.Bimface.Viewer.Viewer2DEvent;
	
		var app = new Glodon.Bimface.Application.WebApplication2D(WebAppConfig);
		viewer = app.getViewer();
		app.load(viewMetaData.viewToken);
	
		// 初始化DrawableContainer
		var drawableConfig = new Glodon.Bimface.Plugins.Drawable.DrawableContainerConfig();
		drawableConfig.viewer = viewer;
		drawableContainer = new Glodon.Bimface.Plugins.Drawable.DrawableContainer(drawableConfig);
		viewer.addEventListener(appEvents.Loaded, function() {
			//   viewer.getComponentProperty("748330", callback)
//			app.render();
			if(type_name == '钢支撑'){
				loadSign1();
			}else{
				loadSign();
			}
	
		});
		viewer.addEventListener(appEvents.MouseClicked, function(objectData) {
			if(!objectData.worldPosition){
				return
			}else {
				if(pointId == null || pointId != -1) {
					return;
				}
	
				//  console.log(objectData, 1);
				var x = objectData.worldPosition.x;
				var y = objectData.worldPosition.y;
				xyz = x + "," + y ;
				if(point_icon){
					var imgs= publicUrl +'file/'+point_icon
				}else{
					var imgs= "../../common/images/circularPointBlue.png"
				}
				drawPoint(pointId, pointNo, isInclinometer, xyz, true, imgs);
	
			}
	
		});
	}

};

function onSDKLoadFailed(error) {

};

//加载标签
function loadSign() {
	pid_point = '';
	$.ajax({
		url: publicUrl + "monitorPoint/listByStation",
		type: "post",
		async: false,
		data: {
			stationId: stationId,
			ptype: ptype
		},
		dataType: "json",
		success: function(data, status) {
			var datas = data.data;
			if(datas == null) {
				return;
			}
			for(var i = 0; i < datas.length; i++) {
				var pointId = datas[i].monitorPointId;
				var pointNo = datas[i].pointNo;
				var xyz = datas[i].gpsCoOrdinates;
				var state = datas[i].state;
				var isInclinometer = datas[i].isInclinometer;
				console.log(picPath)
				var img = picPath+"circularPointGray.png";
				if(ptype == 3){
					if(point_icon){
						img = publicUrl +'file/'+point_icon;
//						img = publicUrl +'/file/'+point_icon;
					}else{
						if(datas[i].icon){
							img = publicUrl +'file/'+datas[i].icon;
//							img = publicUrl +'file/'+datas[i].icon;
						}else{
//							if(datas[i].dateState == 1) {
//								img = picPath+'circularPointGreed.png';
//							} else if(datas[i].dateState == 2) {
//								img = picPath+'circularPointYellow.png';
//							} else if(datas[i].dateState == 3) {
//								img = picPath+'circularPointOrange.png';
//							} else if(datas[i].dateState == 4) {
//								img = picPath+'circularPointRed.png';
//							}
						}
					}
				}else{
					if(datas[i].dateState == 1) {
						img = picPath+'circularPointGreed.png';
					} else if(datas[i].dateState == 2) {
						img = picPath+'circularPointYellow.png';
					} else if(datas[i].dateState == 3) {
						img = picPath+'circularPointOrange.png';
					} else if(datas[i].dateState == 4) {
						img = picPath+'circularPointRed.png';
					}
				}

				if(xyz != null) {
					drawPoint(pointId, pointNo, isInclinometer, xyz, true, img);
				}

			}
		},
		error: function(data) {
			alert("loadSign出错");
		}
	});

}
function loadSign1() {
	$.ajax({
		url: publicUrl + "steelSupport/listAll",
		type: "post",
		async: false,
		data: {
			stationId: stationId,
		},
		dataType: "json",
		success: function(data, status) {
			var datas = data.data;
			if(datas == null) {
				return;
			}
			for(var i = 0; i < datas.length; i++) {
				var pointId = datas[i].steelSupportId;
				var pointNo = datas[i].supportNo;
				var xyz = datas[i].gpsCoOrdinates;
				var state = datas[i].state;
				var isInclinometer = datas[i].isInclinometer;
				console.log(picPath)
				var img = picPath+"circularPointGray.png";
					if(point_icon){
						img = publicUrl +'file/'+point_icon;
//						img = publicUrl +'/file/'+point_icon;
					}else{
						if(datas[i].icon){
							img = publicUrl +'file/'+datas[i].icon;
//							img = publicUrl +'file/'+datas[i].icon;
						}else{
							if(datas[i].dateState == 1) {
								img = picPath+'circularPointGreed.png';
							} else if(datas[i].dateState == 2) {
								img = picPath+'circularPointYellow.png';
							} else if(datas[i].dateState == 3) {
								img = picPath+'circularPointOrange.png';
							} else if(datas[i].dateState == 4) {
								img = picPath+'circularPointRed.png';
							}
						}
					}

				if(xyz != null) {
					drawPoint(pointId, pointNo, isInclinometer, xyz, true, img);
				}

			}
		},
		error: function(data) {
			alert("loadSign出错");
		}
	});

}

// 根据id获取测点
function loadPointDataForId(id) {
		if(type_name == '钢支撑'){
				$.ajax({
			url: publicUrl + "steelSupport/listByIds",
			type: "post",
			async: false,
			data: {
				ids : id,
			},
			dataType: "json",
			success: function(data, status) {
				var datas = data.data;
				if(datas == null) {
					return;
				}
				for(var i = 0; i < datas.length; i++) {
					var pointId = datas[i].steelSupportId;
					var pointNo = datas[i].supportNo;
					var xyz = datas[i].gpsCoOrdinates;
					var state = datas[i].state;
					var isInclinometer = datas[i].isInclinometer;
					console.log(picPath)
					var img = picPath+"circularPointGray.png";
						if(point_icon){
							img = publicUrl +'/file/'+point_icon;
	//						img = publicUrl +'/file/'+point_icon;
						}else{
							if(datas[i].icon){
								img = publicUrl +'file/'+datas[i].icon;
	//							img = publicUrl +'file/'+datas[i].icon;
							}else{
								if(datas[i].dateState == 1) {
									img = picPath+'circularPointGreed.png';
								} else if(datas[i].dateState == 2) {
									img = picPath+'circularPointYellow.png';
								} else if(datas[i].dateState == 3) {
									img = picPath+'circularPointOrange.png';
								} else if(datas[i].dateState == 4) {
									img = picPath+'circularPointRed.png';
								}
							}
						}
	
					if(xyz && xyz != null) {
						drawPoint(pointId, pointNo, isInclinometer, xyz, true, img);
					}
	
				}
			},
			error: function(data) {
				alert("loadSign出错");
			}
		});
		return false;
	}
	pid_point = id;
	$.ajax({
		url: publicUrl + "monitorPoint/listByStation",
		type: "post",
		async: false,
		data: {
			pid: id,
			ptype: ptype
		},
		dataType: "json",
		success: function(data, status) {
			var datas = data.data;
			console.log(datas);
			for(var i = 0; i < datas.length; i++) {
				var pointId = datas[i].monitorPointId;
				var pointNo = datas[i].pointNo;
				var xyz = datas[i].gpsCoOrdinates;
				var state = datas[i].state;
				var isInclinometer = datas[i].isInclinometer;
				var img = picPath+"circularPointGray.png";
				if(ptype == 3){
					if(point_icon){
						img = publicUrl +'/file/'+point_icon;
//						img = publicUrl +'/file/'+point_icon;
					}else{
						if(datas[i].icon){
							img = publicUrl +'/file/'+datas[i].icon;
//							img = publicUrl +'file/'+datas[i].icon;
						}else{
//							if(datas[i].dateState == 1) {
//								img = picPath+'circularPointGreed.png';
//							} else if(datas[i].dateState == 2) {
//								img = picPath+'circularPointYellow.png';
//							} else if(datas[i].dateState == 3) {
//								img = picPath+'circularPointOrange.png';
//							} else if(datas[i].dateState == 4) {
//								img = picPath+'circularPointRed.png';
//							}
						}
					}
				}else{
					if(datas[i].dateState == 1) {
						img = picPath+'circularPointGreed.png';
					} else if(datas[i].dateState == 2) {
						img = picPath+'circularPointYellow.png';
					} else if(datas[i].dateState == 3) {
						img = picPath+'circularPointOrange.png';
					} else if(datas[i].dateState == 4) {
						img = picPath+'circularPointRed.png';
					}
				}
//				if(datas[i].dateState == 1) {
//					img = picPath+'circularPointGreed.png';
//				} else if(datas[i].dateState == 2) {
//					img = picPath+'circularPointYellow.png';
//				} else if(datas[i].dateState == 3) {
//					img = picPath+'circularPointOrange.png';
//				} else if(datas[i].dateState == 4) {
//					img = picPath+'circularPointRed.png';
//				}
				if(xyz != null) {
					drawPoint(pointId, pointNo, isInclinometer, xyz, true, img);
				}

			}
		},
		error: function(data) {}
	});
}

// 绘制测点
function drawPoint(pointId, pointNo, isInclinometer, xyz, boolDelete, img) {
	if(modelLx){
		 worldPosition = {
				x: xyz.split(",")[0],
				y: xyz.split(",")[1],
				z: xyz.split(",")[2]
			};
	} else{
		 worldPosition = {
					x: xyz.split(",")[0],
					y: xyz.split(",")[1]
				};
	}
	var config = new Glodon.Bimface.Plugins.Drawable.CustomItemConfig();
	// 创建自定义元素，可以是一个dom element，也可以是个字符串
	// ***************************************************
	var circle = document.createElement('div');
	circle.style.width = '20px';
	circle.style.height = '20px';
	circle.style.borderRadius = '10%';
	// circle.style.background = '#A2B5CD';
	// circle.style.backgroundImage = 'url(img/circularPointGreed.png);background-size:100%;background-repeat: no-repeat;background-position: center center';
	var problemname = "自定义标签"; //问题主题
	if(pointId != -1) {
		circle.innerHTML = '<img src="' + img + '" style="width:20px;height:20px;" onmouseout="pointOut()" onmousemove="pointNowData(\'' + pointId + '\',\'' + pointNo + '\', \'' + isInclinometer + '\', event,this)" onClick="loadPointData(\'' + pointId + '\',\'' + isInclinometer + '\')"/>';
	} else {
		circle.innerHTML = '<img src="' + img + '" style="width:20px;height:20px;" />';
	}

	config.content = circle;
	config.id = pointId;
	// ****************************************************

	config.viewer = viewer;
	//增加一个Tip提示
	// config.tooltip = '<span class="abc" style="heiht:50px;line-height:50px;display:block;color:#F500;text-align:center">2432432432</span>';
	config.worldPosition = worldPosition;

	//生成customItem实例
	var customItem = new Glodon.Bimface.Plugins.Drawable.CustomItem(config);

	customItem.setOffsetX(-10);
	customItem.setOffsetY(-10);
	//自定义标签的鼠标左键事件
	customItem.onClick(function(item) {
		// drawableContainer.removeItemById(item.id);
		// console.log(item.id);
		// alert('left click');
	});

	//自定义标签的鼠标右键事件
	customItem.onRightClick(function(item) {
		//  alert('right click');
	});

	// 添加自定义标签
	if(boolDelete) {
		drawableContainer.removeItemById(pointId);
	}
	drawableContainer.addItem(customItem)
	//设置Tip的样式
	customItem.setTooltipStyle({
		border: '1px'
	});
}

function clearDraw() {
	drawableContainer.clear();
}

//重新渲染表单
function renderForm() {
	layui.use('form', function() {
		var form = layui.form; //高版本建议把括号去掉，有的低版本，需要加()
		form.render("select");
	});
}

// 鼠标移动在点上
var currentNode = null;

function pointNowData(id, pointNo, isInclinometer, event, obj) {
	if(type_name == '钢支撑') return false;
	//if(isInclinometer == 1) return false;
	var x = event.x + 10;
	var y = event.y + 10;
	// console.log(id);
	if(currentNode == null) {
		$.ajax({
			url: publicUrl + "measureData/getPointLastData",
			type: "post",
			async: false,
			data: {
				pointId: id,
				type: ptype
			},
			dataType: "json",
			success: function(data, status) {
				// console.log(data);
				var datas = data.data;
				var str = "";
				if(datas != null) {
					var stateName = "";
					if(datas.dateState == 1) {
						stateName = "正常";
					} else if(datas.dateState == 2) {
						stateName = "预警";
					} else if(datas.dateState == 3) {
						stateName = "预报";
					} else if(datas.dateState == 4) {
						stateName = "超限";
					}
					if(isInclinometer == 1){
						str = "<p>断面/测点/测线：" + datas.no + "</p>" +
						"<p>最新测量时间：" + datas.testDate + "</p>";
					}else{
						if(ptype == 1) {
							str = "<p>断面/测点/测线：" + datas.no + "</p>" +
								"<p>状态：" + stateName + "</p>" +
								"<p> 本次测量值：" + datas.currentValue + "</p>" +
								"<p> 日变化量：" + datas.dRate + "</p>" +
								"<p> 累积变化量：" + datas.totalDValue + "</p>" +
								"<p>测量时间：" + datas.testDate + "</p>";
						} else {
							str = "<p>测点编号：" + datas.no + "</p>" +
								"<p>状态：" + stateName + "</p>" +
								"<p> 本次测量值：" + datas.currentValue + "</p>" +
								"<p> 日变化量：" + datas.dRate + "</p>" +
								"<p> 累积变化量：" + datas.totalDValue + "</p>" +
								"<p>测量时间：" + datas.testDate + "</p>";
						}
					}
					
					if(ptype != 3){
						if(datas.dateState == 1) {
							obj.src = '' + picPath + 'circularPointGreed.png';
						} else if(datas.dateState == 2) {
							obj.src = '' + picPath + 'circularPointYellow.png';
						} else if(datas.dateState == 3) {
							obj.src = '' + picPath + 'circularPointOrange.png';
						} else if(datas.dateState == 4) {
							obj.src = '' + picPath + 'circularPointRed.png';
						}
					}
					
				} else {
					if(ptype == 1) {
						str = "<p>断面/测点/测线：" + pointNo + "</p>";
					} else {
						str = "<p>测点编号：" + pointNo + "</p>";
					}
				}
				document.getElementById("textDiv").innerHTML = str;
			},
			error: function(data) {}
		});

	}
	$("#textDiv").css({
		left: x + "px",
		top: y + "px",
		display: "block"
	});
	currentNode = id;
	// console.log(obj);

}

// 鼠标移除点
function pointOut() {
	currentNode = null;
	$("#textDiv").css({
		display: "none"
	});
}
var flags=true

function createDiv(num) {
	if(flags){
		flags = false;
	}else{
		return false;
	}
	//document.getElementsByClassName("layui-layer-page layui-layer-content").css({overflow:" hidden !important"});
	//  $(".layui-layer-page .layui-layer-content").css({overflow:"hidden !important"});
	var div = document.createElement("div");
	div.style.width = '300px';
	div.style.height = '180px';
	div.style.background = '#A2B5CD';
	div.id = "textDiv";
	// div.innerHTML = "123";
	div.style.position = "absolute";
	div.style.top = "20px";
	div.style.left = "20px";
	div.style.padding = "10px 0 0 10px";
	div.style.display = "none";
	div.style.zIndex = "9999999";
	document.body.appendChild(div);

	//  总div
	var pointDataDialog = document.createElement("div");
	pointDataDialog.id = "div_pointMessage";
	pointDataDialog.style.display = "none";
	pointDataDialog.style.padding = "10px 10px 0 10px";
	pointDataDialog.width = "700px";
	pointDataDialog.height = "500px";
	document.body.appendChild(pointDataDialog);

	// 条件div
	var queryDiv = document.createElement("div");
	queryDiv.id = "div_query";
	queryDiv.width = "20px";
	queryDiv.height = "20px";
	queryDiv.className = 'layui-form';
	queryDiv.setAttribute('lay-filter','startTime')
	queryDiv.style.marginTop = "5px";
	queryDiv.style.marginLeft = "10px";
	document.getElementById("div_pointMessage").appendChild(queryDiv);

	// 空格
	var spaceText_0 = document.createElement("span");
	spaceText_0.innerHTML = "  ";
	document.getElementById("div_query").appendChild(spaceText_0);

	var startTimeText = document.createElement("span");
	if(type_name == '钢支撑') {
		startTimeText.innerHTML = "时间：";
		document.getElementById("div_query").appendChild(startTimeText);
		var startTimeInput = document.createElement("select");
		startTimeInput.id = "_startTime";
		startTimeInput.innerHTML = "<option value='1'>今天</option><option value='2'>三天内</option><option value='3'>一周内</option><option value='4'>一月内</option><option value='5'>全部</option>";
		// startTimeInput.style.width = "150px";
		// startTimeInput.setAttribute("class","layui-input");
		document.getElementById("div_query").appendChild(startTimeInput);
		layui.use('form',function(){layui.form.render('select','startTime')})
		var queryBtn = document.createElement("button");
		queryBtn.id = "queryBtn";
		queryBtn.setAttribute("class", "xiu_btn_same");
		if(num == 1) {
			queryBtn.innerHTML = '<img src="../../common/images/Buttonico/Butt_Search.png" />查询';
		} else {
			queryBtn.innerHTML = '<img src="../../../common/images/Buttonico/Butt_Search.png" />查询';
		}
		document.getElementById("div_query").appendChild(queryBtn);
	
		// 表格
		var pointDataTab = document.createElement("table");
		pointDataTab.id = "tab_pointMessage";
		document.getElementById("div_pointMessage").appendChild(pointDataTab);
		document.getElementById("tab_pointMessage").setAttribute("lay-filter", "tab_pointMessage_filter");
		return false;
	}
	startTimeText.innerHTML = "开始时间：";
	document.getElementById("div_query").appendChild(startTimeText);

	// 开始时间
	var startTimeInput = document.createElement("input");
	startTimeInput.id = "_startTime";
	startTimeInput.type = "text";
	startTimeInput.innerHTML = "123";
	// startTimeInput.style.width = "150px";
	// startTimeInput.setAttribute("class","layui-input");
	document.getElementById("div_query").appendChild(startTimeInput);

	// 空格
	var spaceText_1 = document.createElement("span");
	spaceText_1.innerHTML = "  ";
	document.getElementById("div_query").appendChild(spaceText_1);

	var endTimeText = document.createElement("span");
	endTimeText.innerHTML = "结束时间：";
	document.getElementById("div_query").appendChild(endTimeText);

	// 结束时间
	var endTimeInput = document.createElement("input");
	endTimeInput.id = "_endTime";
	endTimeInput.type = "text";
	endTimeInput.setAttribute("disable", "disable");
	// endTimeInput.style.width = "150px";
	//endTimeInput.setAttribute("class","layui-input");
	document.getElementById("div_query").appendChild(endTimeInput);

	// 空格
	var spaceText_2 = document.createElement("span");
	spaceText_2.innerHTML = "  ";
	document.getElementById("div_query").appendChild(spaceText_2);

	var queryBtn = document.createElement("button");
	queryBtn.id = "queryBtn";
	queryBtn.setAttribute("class", "xiu_btn_same");
	if(num == 1) {
		queryBtn.innerHTML = '<img src="../../common/images/Buttonico/Butt_Search.png" />查询';
	} else {
		queryBtn.innerHTML = '<img src="../../../common/images/Buttonico/Butt_Search.png" />查询';
	}
	document.getElementById("div_query").appendChild(queryBtn);

	// 表格
	var pointDataTab = document.createElement("table");
	pointDataTab.id = "tab_pointMessage";
	document.getElementById("div_pointMessage").appendChild(pointDataTab);
	document.getElementById("tab_pointMessage").setAttribute("lay-filter", "tab_pointMessage_filter");

	
	//  总div
	var pointDataDialog = document.createElement("div");
	pointDataDialog.id = "div_pointMessage1";
	pointDataDialog.style.display = "none";
	pointDataDialog.style.padding = "10px 10px 0 10px";
	pointDataDialog.width = "700px";
	pointDataDialog.height = "500px";
	document.body.appendChild(pointDataDialog);
	
	// 条件div对于测斜单独设置
	var queryDiv = document.createElement("div");
	queryDiv.id = "div_querysounding";
	queryDiv.width = "20px";
	queryDiv.height = "20px";
	queryDiv.className = 'layui-form';
	queryDiv.setAttribute('lay-filter','date')
	queryDiv.style.marginTop = "5px";
	queryDiv.style.marginLeft = "10px";
	document.getElementById("div_pointMessage1").appendChild(queryDiv);

	var queryDiv1 = document.createElement("div");
	queryDiv1.className = 'layui-form-item';
	queryDiv1.style.marginTop = "5px";
	queryDiv1.style.marginLeft = "10px";
	document.getElementById("div_querysounding").appendChild(queryDiv1);
	
	// 空格
	var spaceText_0 = document.createElement("span");
	spaceText_0.innerHTML = "  ";
	queryDiv1.appendChild(spaceText_0);
	
	var date = document.createElement("label");
	date.innerHTML = "监测时间：";
	date.className = 'layui-form-label';
	queryDiv1.appendChild(date);
	
	var queryDiv2 = document.createElement("div");
	queryDiv2.className = 'layui-input-inline';
	queryDiv1.appendChild(queryDiv2);
	
	var startTimeInput = document.createElement("select");
	startTimeInput.id = "date";
	startTimeInput.name = "date";
	startTimeInput.innerHTML = "";
	// startTimeInput.style.width = "150px";
	// startTimeInput.setAttribute("class","layui-input");
	queryDiv2.appendChild(startTimeInput);
	layui.use('form',function(){layui.form.render('select','date')})
	var queryBtn1 = document.createElement("button");
	queryBtn1.style.marginLeft = "10px";
	queryBtn1.id = "queryBtnSounding";
	queryBtn1.setAttribute("class", "xiu_btn_same");
	if(num == 1) {
		queryBtn1.innerHTML = '<img src="../../common/images/Buttonico/Butt_Search.png" />查询';
	} else {
		queryBtn1.innerHTML = '<img src="../../../common/images/Buttonico/Butt_Search.png" />查询';
	}
	queryDiv1.appendChild(queryBtn1);

	//bxf于2019.2.24注释  侧深改
	/*// 条件div
	var queryDiv = document.createElement("div");
	queryDiv.id = "div_query1";
	queryDiv.width = "20px";
	queryDiv.height = "20px";
	queryDiv.style.marginTop = "5px";
	queryDiv.style.marginLeft = "10px";
	document.getElementById("div_pointMessage1").appendChild(queryDiv);

	// 空格
	var spaceText_01 = document.createElement("span");
	spaceText_01.innerHTML = "  ";
	document.getElementById("div_query1").appendChild(spaceText_01);

	var startTimeText1 = document.createElement("span");
	startTimeText1.innerHTML = "开始时间：";
	document.getElementById("div_query1").appendChild(startTimeText1);

	// 开始时间
	var startTimeInput1 = document.createElement("input");
	startTimeInput1.id = "_startTime1";
	startTimeInput1.type = "text";
	startTimeInput1.innerHTML = "123";
	// startTimeInput.style.width = "150px";
	// startTimeInput.setAttribute("class","layui-input");
	document.getElementById("div_query1").appendChild(startTimeInput1);

	// 空格
	var spaceText_11 = document.createElement("span");
	spaceText_11.innerHTML = "  ";
	document.getElementById("div_query1").appendChild(spaceText_11);

	var endTimeText1 = document.createElement("span");
	endTimeText1.innerHTML = "结束时间：";
	document.getElementById("div_query1").appendChild(endTimeText1);

	// 结束时间
	var endTimeInput1 = document.createElement("input");
	endTimeInput1.id = "_endTime1";
	endTimeInput1.type = "text";
	endTimeInput1.setAttribute("disable", "disable");
	// endTimeInput.style.width = "150px";
	//endTimeInput.setAttribute("class","layui-input");
	document.getElementById("div_query1").appendChild(endTimeInput1);

	// 空格
	var spaceText_21 = document.createElement("span");
	spaceText_21.innerHTML = "  ";
	document.getElementById("div_query1").appendChild(spaceText_21);

	var queryBtn1 = document.createElement("button");
	queryBtn1.id = "queryBtn1";
	queryBtn1.setAttribute("class", "xiu_btn_same");
	if(num == 1) {
		queryBtn1.innerHTML = '<img src="../../common/images/Buttonico/Butt_Search.png" />查询';
	} else {
		queryBtn1.innerHTML = '<img src="../../../common/images/Buttonico/Butt_Search.png" />查询';
	}
	document.getElementById("div_query1").appendChild(queryBtn1);*/

	// 表格
	var pointDataTab1 = document.createElement("table");
	pointDataTab1.id = "tab_pointMessage1";
	document.getElementById("div_pointMessage1").appendChild(pointDataTab1);
	document.getElementById("tab_pointMessage1").setAttribute("lay-filter", "tab_pointMessage_filte1");

	layui.use('laydate', function() {
		var laydate = layui.laydate;

		//执行一个laydate实例
		laydate.render({
			elem: '#_startTime', //指定元素
		});

		laydate.render({
			elem: '#_endTime', //指定元素
		});
		//执行一个laydate实例
		laydate.render({
			elem: '#_startTime1', //指定元素
		});

		laydate.render({
			elem: '#_endTime1', //指定元素
		});
	});
}

// 加载测点数据
function loadPointData(pointId, isInclinometer) {
	document.getElementById("queryBtn").setAttribute("onClick", "refrashPointData(\'" + pointId + "\',\'" + isInclinometer + "\')");
	if(isInclinometer==1){
		layer.open({
			type: 1,
			title: '监测数据',
			//          maxmin: true,
			//        shadeClose: true, //点击遮罩关闭层
			area: ['1100px', '600px'],
			content: $('#div_pointMessage1'),
			// btn: ['确定'],
			success: function(index, layero) {
				$('#_startTime,#_endTime').val('');
				getPointData(pointId, isInclinometer);
			}
		});
	}else{
		layer.open({
			type: 1,
			title: '监测数据',
			//          maxmin: true,
			//        shadeClose: true, //点击遮罩关闭层
			area: ['1100px', '600px'],
			content: $('#div_pointMessage'),
			// btn: ['确定'],
			success: function(index, layero) {
				$('#_startTime,#_endTime').val('');
				getPointData(pointId, isInclinometer);
			}
		});
	}
	
}

// 获取测点监测数据
function getPointData(pointId, isInclinometer) {
	if(type_name == '钢支撑'){
		layui.use('table', function() {
			var table = layui.table;
			table.render({
				elem: '#tab_pointMessage',
				width: "1080",
				height: "480",
				method: 'post',
				url: publicUrl + 'servoData/listRealTime',
				request: {
					limitName: 'rows'
				},
				where: {
					supportId : pointId,
					dateType : $("#_startTime").val()
				},
				response: {
					statusName: 'code',
					statusCode: 200,
					countName: 'total'
				},
				cols: [
					[{
							title: '序号',
							type: 'numbers',
							align: 'center',
							width: 60
						},
						{
							field: 'supportNo',
							title: '钢支撑编号',
							align: 'center',
							sort: true
						},
						{
							field: 'tension',
							title: '轴力(KN)',
							align: 'center',
							sort: true,
							templet: function(d) {
								if(d.tension > d.maxPower || d.tension < d.minPower){
		                			return '<span style="color:red">'+d.tension+'</span>'
		                		}else{
									return d.tension
								}
							}
						},
						{
							field: 'elongation',
							title: '行程(mm)',
							align: 'center',
							sort: true
						},
						{
							field: 'statusName',
							title: '状态',
							align: 'center',
							sort: true,
							templet: function(d) {
								if(d.statusName == '位移超行程' || d.statusName == '无法加压' || d.statusName == '压力过大' || d.statusName == '油泵电机故障'){
		                			return '<span style="color:red">'+d.statusName+'</span>'
		                		}else{
									return d.statusName
								}
							}
						},
						{
							field: 'measureDate',
							title: '监测时间',
							align: 'center',
							sort: true
						}
					]
				],
				page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
					layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'] //自定义分页布局
				},
				done: function(res, curr, count) {
				}
			});
		})
		return false;
	}
	var startTime = $('#_startTime').val();
	var endTime = $('#_endTime').val();
	if(startTime == "" || endTime == "") {
		startTime = null;
		endTime = null;
	}
	var wheres, urls;
	if(ptype == 1) {
		urls = 'tunnel/listMeasureDate';
		wheres = {
			tunnelSectionIds: pid_point,
			pointId: pointId,
			beginDate: startTime,
			endDate: endTime
		}
	} else if(ptype == 2) {
		urls = 'pier/listMeasureDate';
		wheres = {
			pierIds: pid_point,
			pointId: pointId,
			beginDate: startTime,
			endDate: endTime
		}
	} else {
		if(isInclinometer == 1) {
			$("#div_query").addClass('hideNone');
			urls = 'measureData/getSoundingLastDataNew';
			wheres = {
				pointId: pointId,
				date:''
			}
			layui.use('table', function() {
				var table = layui.table;
				table.render({
					elem: '#tab_pointMessage1',
					width: "1080",
					height: "480",
					method: 'post',
					url: publicUrl + urls,
					request: {
						limitName: 'rows'
					},
					where: wheres,
					response: {
						statusName: 'code',
						statusCode: 200,
						countName: 'total'
					},
					cols: [
						[{
								title: '序号',
								type: 'numbers',
								align: 'center',
								width: 60
							},
							{
								field: 'sounding',
								title: '侧深编号',
								align: 'center',
								sort: true
							},
							{
								field: 'currentValue',
								title: '本次测量值(mm)',
								align: 'center',
								sort: true
							},
							{
								field: 'totalValue',
								title: '累计变化量(mm)',
								align: 'center',
								sort: true
							},
							{
								field: 'rate',
								title: '变化量速率(mm/d)',
								align: 'center',
								sort: true
							}
							/*,
							{
								field: 'dateStateName',
								title: '数据状态',
								align: 'center',
								width: 100,
								sort: true,
								templet: function(d) {
									var str = "";
									if(d.dateState == 1) {
										str = '<image src =' + picPath + 'circularPointGreed.png style="width:20px;height:20px;"/>';
									} else if(d.dateState == 2) {
										str = '<image src =' + picPath + 'circularPointYellow.png style="width:20px;height:20px;"/>';
									} else if(d.dateState == 3) {
										str = '<image src =' + picPath + 'circularPointOrange.png style="width:20px;height:20px;"/>';
									} else if(d.dateState == 4) {
										str = '<image src =' + picPath + 'circularPointRed.png style="width:20px;height:20px;"/>';
									}
									return str;
									//return 'ID：'+ d.id +'，标题：<span style="color: #c00;">'+ d.title +'</span>'
								}
							},
							{
								field: 'testDate',
								title: '测量时间',
								align: 'center',
								sort: true
							},
							{
								title: '操作',
								align: 'center',
								width: 60,
								templet: function(d) {
									if(num == 1) {
										return '<img lay-event="detailRetest" title="详情" src="../../common/images/Buttonico/butt_op_detail.png" />';
									} else {
										return '<img lay-event="detailRetest" title="详情" src="../../../common/images/Buttonico/butt_op_detail.png" />';
									}
								}
							}*/
						]
					],
					/*page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
						layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'] //自定义分页布局
					},*/
					done: function(res, curr, count) {
						if(ptype == 1) {
							$("#div_pointMessage .layui-table-header thead tr:first th:nth-child(2) span:first").text('断面/测点/测线');
						} else {
							$("#div_pointMessage .layui-table-header thead tr:first th:nth-child(2) span:first").text('测点编号');
						}
						var mydata = {
								pointId: pointId
						}
						$.ajax({
							type:'post',
							url:'/olm/measureData/getAllTestDate',
							data:mydata,
							success:function(r){
								var myoption = "<option value=''>请选择</option>";
								var mydata = r.data;
								$.each(mydata,function(i,e){
									myoption += '<option value="'+ e.testDate +'">'+ e.testDate +'</option>';
								});
								$("select[name=date]").html("");
								$("select[name=date]").append(myoption);
								layui.use('form',function(){layui.form.render('select','date')})
							}
						})
					}
				});
				
				$("#queryBtnSounding").click(function(){
					wheres = {
							pointId: pointId,
							date:$("#date").val()
						}
					table.render({
						elem: '#tab_pointMessage1',
						width: "1080",
						height: "480",
						method: 'post',
						url: publicUrl + urls,
						request: {
							limitName: 'rows'
						},
						where: wheres,
						response: {
							statusName: 'code',
							statusCode: 200,
							countName: 'total'
						},
						cols: [
							[{
									title: '序号',
									type: 'numbers',
									align: 'center',
									width: 60
								},
								{
									field: 'sounding',
									title: '侧深编号',
									align: 'center',
									sort: true
								},
								{
									field: 'currentValue',
									title: '本次测量值(mm)',
									align: 'center',
									sort: true
								},
								{
									field: 'totalValue',
									title: '累计变化量(mm)',
									align: 'center',
									sort: true
								},
								{
									field: 'rate',
									title: '变化量速率(mm/d)',
									align: 'center',
									sort: true
								}
							]
						],
						done: function(res, curr, count) {
							if(ptype == 1) {
								$("#div_pointMessage .layui-table-header thead tr:first th:nth-child(2) span:first").text('断面/测点/测线');
							} else {
								$("#div_pointMessage .layui-table-header thead tr:first th:nth-child(2) span:first").text('测点编号');
							}
						}
					});
				})
				table.on('tool(tab_pointMessage_filter)', function(obj) {
					var data = obj.data; //获得当前行数据
					var pointId = data.pointId;
					var soundingId = data.soundingId;
					if(obj.event === 'detailRetest') {
						document.getElementById("queryBtn1").setAttribute("onClick", "refrashPointData1(\'" + pointId + "\',\'" + soundingId + "\')");
						var layindex = layer.open({
							type: 1,
							title: '监测数据',
							area: ['1100px', '600px'],
							content: $('#div_pointMessage1'),
							success: function(layero, index) {
								$('#_startTime1,#_endTime1').val('');
								getDeeplist(pointId,soundingId);
							},
							cancel: function(index, layero) {
							}
						});
//						layer.full(layindex);
					}
				});
			});
			return false;
		} else {
			$("#div_query").removeClass('hideNone');
			urls = 'ditch/listMeasureDate';
			wheres = {
				ditchIds: pid_point,
				pointId: pointId,
				beginDate: startTime,
				endDate: endTime
			}
		}
	}
	layui.use('table', function() {
		var table = layui.table;
		table.render({
			elem: '#tab_pointMessage',
			width: "1080",
			height: "480",
			method: 'post',
			url: publicUrl + urls,
			request: {
				limitName: 'rows'
			},
			where: wheres,
			response: {
				statusName: 'code',
				statusCode: 200,
				countName: 'total'
			},
			cols: [
				[{
						title: '序号',
						type: 'numbers',
						align: 'center',
						width: 60
					},
					{
						field: 'no',
						title: '测点编号',
						align: 'center',
						width: 150,
						sort: true
					},
					{
						field: 'currentValue',
						title: '本次测量值(mm)',
						align: 'center',
						width: 150,
						sort: true
					},
					{
						field: 'currentDValue',
						title: '日变化量(mm)',
						align: 'center',
						width: 150,
						sort: true
					},
					{
						field: 'totalDValue',
						title: '累计变化量(mm)',
						align: 'center',
						width: 150,
						sort: true
					},
					{
						field: 'dateStateName',
						title: '数据状态',
						align: 'center',
						width: 100,
						sort: true,
						templet: function(d) {
							var str = "";
							if(d.dateState == 1) {
								str = '<image src =' + picPath + 'circularPointGreed.png style="width:20px;height:20px;"/>';
							} else if(d.dateState == 2) {
								str = '<image src =' + picPath + 'circularPointYellow.png style="width:20px;height:20px;"/>';
							} else if(d.dateState == 3) {
								str = '<image src =' + picPath + 'circularPointOrange.png style="width:20px;height:20px;"/>';
							} else if(d.dateState == 4) {
								str = '<image src =' + picPath + 'circularPointRed.png style="width:20px;height:20px;"/>';
							}
							return str;
							//return 'ID：'+ d.id +'，标题：<span style="color: #c00;">'+ d.title +'</span>'
						}
					},
					{
						field: 'testDate',
						title: '测量时间',
						align: 'center',
						sort: true
					}
				]
			],
			page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
				layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'] //自定义分页布局
			},
			done: function(res, curr, count) {
				if(ptype == 1) {
					$("#div_pointMessage .layui-table-header thead tr:first th:nth-child(2) span:first").text('断面/测点/测线');
				} else {
					$("#div_pointMessage .layui-table-header thead tr:first th:nth-child(2) span:first").text('测点编号');
				}
			}
		});
	});

}
function getDeeplist(pointId,soundingId){
	var startTime = $('#_startTime1').val();
	var endTime = $('#_endTime1').val();
	if(startTime == "" || endTime == "") {
		startTime = null;
		endTime = null;
	}
	layui.use('table', function() {
		var table = layui.table;
		table.render({
			elem: '#tab_pointMessage1',
			width: "1080",
			height: "480",
			method: 'post',
			url: publicUrl + 'ditch/listMeasureDate',
			request: {
				limitName: 'rows'
			},
			where: {
				ditchIds: pid_point,
				pointId: pointId,
				beginDate: startTime,
				endDate: endTime,
				soundingId: soundingId
			},
			response: {
				statusName: 'code',
				statusCode: 200,
				countName: 'total'
			},
			cols: [
				[{
						title: '序号',
						type: 'numbers',
						align: 'center',
						width: 60
					},
					{
						field: 'pointNo',
						title: '测深编号',
						align: 'center',
						sort: true
					},
					{
						field: 'currentValue',
						title: '本次测量值(mm)',
						align: 'center',
						width: 150,
						sort: true
					},
					{
						field: 'currentDValue',
						title: '日变化量(mm)',
						align: 'center',
						width: 150,
						sort: true
					},
					{
						field: 'totalDValue',
						title: '累计变化量(mm)',
						align: 'center',
						width: 150,
						sort: true
					},
					{
						field: 'dateStateName',
						title: '数据状态',
						align: 'center',
						width: 100,
						sort: true,
						templet: function(d) {
							var str = "";
							if(d.dateState == 1) {
								str = '<image src =' + picPath + 'circularPointGreed.png style="width:20px;height:20px;"/>';
							} else if(d.dateState == 2) {
								str = '<image src =' + picPath + 'circularPointYellow.png style="width:20px;height:20px;"/>';
							} else if(d.dateState == 3) {
								str = '<image src =' + picPath + 'circularPointOrange.png style="width:20px;height:20px;"/>';
							} else if(d.dateState == 4) {
								str = '<image src =' + picPath + 'circularPointRed.png style="width:20px;height:20px;"/>';
							}
							return str;
							//return 'ID：'+ d.id +'，标题：<span style="color: #c00;">'+ d.title +'</span>'
						}
					},
					{
						field: 'testDate',
						title: '测量时间',
						align: 'center',
						sort: true
					}
				]
			],
			page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
				layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'] //自定义分页布局
			},
			done: function(res, curr, count) {
			}
		});
	})
}
function refrashPointData(pointId, isInclinometer) {
	getPointData(pointId, isInclinometer);
}
function refrashPointData1(pointId, soundingId) {
	getDeeplist(pointId,soundingId);
}
function setBackgroundColor(){
	viewer.setBackgroundColor(new Glodon.Web.Graphics.Color(255, 255, 255, 1));
}